<template>
  <div class="dinDrtail">
    <div class="drtailtop">
      <div class="left">
        <img
          src="../../../assets/img/navbar/logo2.png"
          @click="goHome"
          class="hll_logo"
        />
      </div>
      <!-- <div class="right" @click="blacknow">
        <div>返回</div>
        <img
          class="righticon"
          src="../../../assets/img/header/linrigt.png"
          alt=""
        />
      </div> -->
    </div>
    <div class="dinDrtailcon">
      <div class="drtailcon">
        <!-- <div class="rtailleft">
        <div class="rtailimgtop">
          <img
            class="rtailimg"
            src="https://file.honglonglong.com.cn/hll_newPc/footerBar/banner4bg.png"
            alt=""
            @click="onPreview"
          />
          <el-image-viewer 
                     v-if="showViewer" 
                     :on-close="closeViewer" 
                     :url-list="['https://file.honglonglong.com.cn/hll_newPc/footerBar/banner4bg.png']" />
          </el-image>
        </div>
        <div class="rtaillefttext">
          <div class="text">{{caseData.title}}</div>
          <div class="number">01/02</div>
        </div>
      </div> -->
        <div class="rtailright">
          <div class="title">{{ caseData.title }}</div>
          <div class="line"></div>
          <div class="createtime">{{ caseData.date }}</div>
          <div
            class="center"
            v-html="caseData.content ? caseData.content : caseData.desc"
          ></div>
        </div>
      </div>
      <div class="projectset">
        <div
          class="proert setShow"
          v-if="caseData.upnews_id"
          @click="fetchData(caseData.upnews_id)"
        >
          <div>上一个 |</div>
          <div class="proertc">
            {{ caseData.upnews_title }}
          </div>
        </div>

        <div
          class="proert setShow"
          v-if="caseData.downnews_id"
          @click="fetchData(caseData.downnews_id)"
        >
          <div class="proertc">
            {{ caseData.downnews_title }}
          </div>
          <div>| 下一个</div>
        </div>
      </div>
    </div>
    <FooterBar class="footerBar"></FooterBar>
  </div>
</template>
<script>
import { getSuccessfulCaseDetail } from "./../../../apis/api.js";
import FooterBar from "../../../components/FooterBar";
import ElImageViewer from "element-ui/packages/image/src/image-viewer";
export default {
  name: "DinDrtail",
  data() {
    return {
      id: "",
      caseData: {},
      showViewer: false, // 显示查看器
    };
  },
  components: {
    FooterBar,
    ElImageViewer,
  },
  mounted() {
    if (!this.$route.query.id) {
      console.error(`id '${this.$route.query.id}' invalid`);
      return;
    }
    this.id = this.$route.query.id;
    this.fetchData(this.id);
  },
  watch: {
    $route() {
      this.fetchData(this.id);
    },
  },
  methods: {
    goHome() {
      this.$router.push({ path: "/homePc" });
    },
    blacknow() {
      this.$router.go(-1);
      console.log("返回");
    },
    onPreview() {
      this.showViewer = true;
    },
    // 关闭查看器
    closeViewer() {
      this.showViewer = false;
    },
    fetchData(id) {
      this.$route.query.id = this.id;

      getSuccessfulCaseDetail(id).then(({ data }) => {
        if (data.result === 1) {
          this.caseData = data.body;
          this.caseData.create_time = this.caseData.create_time.split(" ")[0];
           this.caseData.content =this.caseData.content.replace(/<img/g,'<img style="width:60%;margin:24px 20% 24px 20%;"');
          document.body.scrollTop = document.documentElement.scrollTop = 0;
          // this.caseData.desc = (this.caseData.desc || "")
          //   .split(/[\r\n]/)
          //   .map((line) => `<p>${line}</p>`)
          //   .join("\n");
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>

.dinDrtail {
  height: 100vh;
  .dinDrtailcon {
    margin: 0 auto;
    max-width: 1140px;
  }
 
  .drtailtop {
    margin: 50px 130px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .hll_logo {
      width: 106px;
      height: 36px;
      cursor: pointer;
      margin-left: 5%;
    }
    .right {
      display: flex;
      align-items: center;
      font-size: 16px;
      font-weight: 400;
      color: #000000;
      cursor: pointer;
      .righticon {
        width: 40px;
        height: 17px;
        margin-left: 20px;
      }
    }
  }
  .drtailcon {
    display: flex;
    justify-content: space-between;
    .rtailleft {
      width: 375px;
      height: 512px;
      background: #ffffff;
      border: 1px solid #ebeef5;
      .rtailimgtop {
        .rtailimg {
          width: 375px;
          height: 411px;
        }
      }
      .rtaillefttext {
        font-size: 16px;
        font-weight: 400;
        color: #000000;
        margin: 10px 20px 20px 20px;
        .number {
          text-align: right;
          font-size: 30px;
          font-weight: 600;
          color: #ff855b;
          margin-top: 10px;
        }
      }
    }
    .rtailright {
      .createtime {
        text-align: right;
        padding-bottom: 20px;
      }

      font-size: 16px;
      font-weight: 400;
      color: #909399;
      margin-left: 30px;
      letter-spacing: 2px;
      .title {
        font-size: 22px;
        font-weight: 500;
        color: #000000;
      }
      .line {
        width: 100%;
        height: 1px;
        background: #ffdcdfe6;
        margin: 30px 0;
      }
      p {
        margin-top: 8px;
        margin-bottom: 16px;
      }
      h2 {
        margin: 30px 0;
      }
      .more-cases {
        background-color: #f0f5ff;
        margin-top: 60px;
        padding: 40px 0;
        .title {
          margin-bottom: 18px;
        }
        .case-list {
          .case {
            img {
              width: 215px;
              height: 125px;
              margin-bottom: 20px;
            }
            .title {
              width: 215px;
            }
          }
        }
      }
      // .center {
      //   margin: 20px 0;
      // }
    }
  }
  .projectset {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    font-weight: 500;
    color: #0c0b0b;
    margin-top: 50px;
    .setShow {
      cursor: pointer;
    }
    .setShow:hover {
      cursor: pointer;
      color: #ffc107;
    }
    .proert {
      display: flex;

      .proertc {
        max-width: 220px;
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        margin: 0 10px;
      }
    }
  }
  .footerBar {
    margin-top: 168px;
  }
}
</style>